<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title></title>


    <style type="text/css">
        .search_input {
            overflow: visible;
            background-color: #FFFFFF;
            background-image: none;
            border: 1px solid #e5e6e7;
            border-radius: 1px;
            color: inherit;
            display: block;
            padding: 6px 12px;
            transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
        }
    </style>
</head>

<body>


<div class="breadcome-area">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="breadcome-list single-page-breadcome">
                    <div class="row">
                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                            <div class="breadcome-heading">
                                <form id="searchForm" role="search" class="sr-input-func">
                                    <input type="text" name="name" placeholder="请输入姓名"
                                           class="search-int form-control">
                                    <a href="javascript:void(0)" onclick="operation.searchForm()"><i
                                            class="fa fa-search"></i></a>

                                </form>
                            </div>
                        </div>
                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                            <ul class="breadcome-menu">
                                <li><a href="#">首页</a> <span class="bread-slash">/</span>
                                </li>
                                <li><span class="bread-blod">设置计划详情</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="mg-b-15">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="product-status-wrap drp-lst">
                    <h4>设置计划详情</h4>
                    <div class="add-product">
                        <a href="#" onclick="operation.addWindow()">添加</a>
                    </div>
                    <div class="asset-inner">

                        <table id="dg"></table>


                    </div>


                </div>
            </div>
        </div>
    </div>
</div>


<!-- 第一个model 开始 -->
<div id="setFormModal" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keybord="false">
    <div class="modal-dialog" style="width:700px">
        <div class="modal-content">
            <div class="modal-header">
                编辑
            </div>
            <!-- modal-body 开始 -->
            <div class="modal-body">
                <form id="setFormId" class="form-horizontal" enctype="multipart/form-data">
                    <input type="hidden" name="id">


                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label text-right" for="planId">计划</label>
                        <div class="col-sm-8">
                            <select class="form-control" id="planId" name="planId"
                                    placeholder="请输入计划主键"></select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label text-right" for="planDetailType">维修部位</label>
                        <div class="col-sm-8">
                            <select class="form-control" name="planDetailType" placeholder="请输入计划类型">
                                <option value="">--请选择--</option>
                                <option value="中检">中检</option>
                                <option value="小检">小检</option>
                                <option value="辅检">辅检</option>
                                <option value="临检">临检</option>
                                <option value="其他">其他</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label text-right" for="trainInfoId">机车编号</label>
                        <div class="col-sm-8">
                            <select class="form-control" id="trainInfoId" name="trainInfoId"
                                    placeholder="请输入机车Id"></select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label text-right" for="cj">车间</label>
                        <div class="col-sm-8">
                            <select class="form-control" name="cj" id="cj" placeholder="车间"
                                    onchange="operation.getCjListBycj()"></select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label text-right" for="repairTypeId">检修清单类型</label>
                        <div class="col-sm-8">
                            <select class="form-control" name="repairTypeId" id="repairTypeId"
                                    placeholder="检修清单类型"></select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label text-right" for="planDetailInfo">详情信息</label>
                        <div class="col-sm-8">
                            <textarea class="form-control" rows="3" name="planDetailInfo"
                                      placeholder="请输入详情信息"></textarea>
                        </div>
                    </div>
                    <!--<div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="planDetailStatus">计划详情状态</label>
                        <div class="col-sm-6">
                            <input class="form-control"  name="planDetailStatus"  placeholder="请输入计划详情状态"/>
                        </div>
                    </div>-->


                </form>
            </div>
            <!-- modal-body 结束 -->
            <div class="modal-footer">
                <button id="add_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operation.addForm()">
                    <span class="glyphicon glyphicon-ok"></span>保存
                </button>
                <button id="edit_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operation.editForm()">
                    <span class="glyphicon glyphicon-ok"></span>保存
                </button>
                <button id="delete_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operation.closeMoal()">
                    <span class="glyphicon glyphicon-remove"></span>关闭
                </button>
            </div>

        </div>
    </div>
</div>
<!-- 第一个model 结束 -->


<!-- 第一个model 开始 -->
<div id="setUserModal" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keybord="false">
    <div class="modal-dialog" style="width:700px">
        <div class="modal-content">
            <div class="modal-header">
                设置检修员
            </div>
            <!-- modal-body 开始 -->
            <div class="modal-body">


                <div class="row">
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                        <div class="product-status-wrap drp-lst">
                            <h4></h4>
                            <div class="add-product">
                                <a href="#" onclick="operationUser.addWindow()">添加</a>
                            </div>
                            <div class="asset-inner">

                                <table id="dgUser"></table>


                            </div>


                        </div>
                    </div>
                </div>


            </div>
            <!-- modal-body 结束 -->
            <div class="modal-footer">

                <button type="button" class="btn btn-default btn-outline btn-sm" onclick="operation.closeUserMoal()">
                    <span class="glyphicon glyphicon-remove"></span>关闭
                </button>
            </div>

        </div>
    </div>
</div>
<!-- 第一个model 结束 -->


<!-- 第一个model 开始 -->
<div id="setUserFormModal" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keybord="false">
    <div class="modal-dialog" style="width:700px">
        <div class="modal-content">
            <div class="modal-header">
                编辑
            </div>
            <!-- modal-body 开始 -->
            <div class="modal-body">
                <form id="setUserFormId" class="form-horizontal" enctype="multipart/form-data">
                    <input type="hidden" name="id">


                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="jobId">岗位</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="jobId" name="jobId" placeholder="请输入岗位"></select>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="departmentId">部门</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="departmentId" name="departmentId"
                                    placeholder="请输入分配人员"></select>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="userId">分配人员</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="userId3" name="userId"
                                    placeholder="请输入分配人员"></select>
                        </div>
                    </div>
                </form>
            </div>
            <!-- modal-body 结束 -->
            <div class="modal-footer">
                <button id="user_add_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operationUser.addForm()">
                    <span class="glyphicon glyphicon-ok"></span>保存
                </button>
                <button id="user_edit_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operationUser.editForm()">
                    <span class="glyphicon glyphicon-ok"></span>保存
                </button>
                <button id="user_delete_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operationUser.closeMoal()">
                    <span class="glyphicon glyphicon-remove"></span>关闭
                </button>
            </div>

        </div>
    </div>
</div>
<!-- 第一个model 结束 -->

<!-- Page-Level Scripts -->
<script type="text/javascript" th:inline="none">
    // getZcxRepairTypeList("repairTypeId")
    getCjList("cj")
    getZcxPlanList("planId")
    getZcxNormalTrainInfoList("trainInfoId");
    // getZcxUserListB("userId3",3);

    getZcxDepartmengList("departmentId")
    getZcxJobList("jobId")

    $("#jobId").change(function () {
        getUser()
    })
    $("#departmentId").change(function () {
        getUser()
    })

    //初始化
    function getZcxUserListB(id, role) {
        $.post("/ZcxUser/findAble", {role: role, planDetailId: planDetailId}, function (data) {
            $('#' + id).empty();
            var html = "";
            html += "<option value=''>--请选择--</option>";
            $.each(data, function (i, val) {
                html += "<option value='" + val.id + "'>" + val.name + "</option>";
            });
            $('#' + id).append(html);
        });
    }

    function getUser() {
        var jobId = $("#jobId").val();
        var departmentId = $("#departmentId").val();
        $.post("/ZcxUser/findAble", {
            jobId: jobId,
            departmentId: departmentId,
            planDetailId: planDetailId
        }, function (data) {
            $('#userId3').empty();
            var html = "";
            html += "<option value=''>--请选择--</option>";
            $.each(data, function (i, val) {
                html += "<option value='" + val.id + "'>" + val.name + "</option>";
            });
            $('#userId3').append(html);
        });
    }


    var planDetailId;
    var operation = {
        getCjListBycj: function () {
            var cj = $("#cj").val();
            $.post("/ZcxRepairType/findList", {cj: cj}, function (data) {
                $('#repairTypeId').empty();
                var html = "";
                html += "<option value=''>--请选择--</option>";
                $.each(data, function (i, val) {
                    html += "<option value='" + val.id + "'>" + val.repairTypeName + "</option>";
                });
                $('#repairTypeId').append(html);
            });
        },
        searchForm: function () {
            $('#dg').bootstrapTable("refresh");
        },
        //弹出添加页面
        addWindow: function () {
            $('#setFormModal').modal('show');
            formObj.setBtnIsShow("add_save_btn", "edit_save_btn", 1);

        },
        //添加表单
        addForm: function () {
            $("#setFormId").bootstrapValidator('validate');
            if ($("#setFormId").data("bootstrapValidator").isValid()) {
                var temp = getFormJson("setFormId");


                $.post("/ZcxPlanDetail/insertZcxPlanDetail", temp, function (data) {

                    $("#dg").bootstrapTable("refresh");
                    message.alert(data.showInfo);
                    $('#setFormId').data('bootstrapValidator').resetForm(true);
                    $('#setFormId')[0].reset();
                    $('#setFormModal').modal('hide');
                });
            }

        },
        //弹出修改页面
        editWindow: function (index) {
            var row = $("#dg").bootstrapTable("getData")[index];
            setForm("#setFormId", row);
            $('#setFormModal').modal('show');
            formObj.setBtnIsShow("add_save_btn", "edit_save_btn", 0);

        },
        //修改表单
        editForm: function () {
            var validate = $("#setFormId").bootstrapValidator('validate');
            if ($("#setFormId").data("bootstrapValidator").isValid()) {
                var temp = getFormJson("setFormId");
                $.post("/ZcxPlanDetail/updateZcxPlanDetail", temp, function (data) {

                    $("#dg").bootstrapTable("refresh");
                    message.alert(data.showInfo);
                    $('#setFormId').data('bootstrapValidator').resetForm(true);
                    $('#setFormId')[0].reset();
                    $('#setFormModal').modal('hide');
                });
            }

        },
        //删除表单
        deleteFrom: function (index) {
            var row = $("#dg").bootstrapTable("getData")[index];
            if (row.planDetailStatus == "完成") {
                message.alert("删除失败，已完成计划，不可删除");
            } else {
                bootbox.confirm({
                    size: "small",
                    title: "提示",
                    message: "确认删除这条数据吗？",
                    callback: function (result) {
                        if (result) {
                            $.post("/ZcxPlanDetail/deleteZcxPlanDetail", {id: row.id}, function (data) {

                                $("#dg").bootstrapTable("refresh");
                                message.alert(data.showInfo);

                            });

                        }
                    }
                });

            }
        },

        closeUserMoal: function () {
            //$('#setFormId').reset();
            $('#setUserModal').modal('hide');
        },
        //关闭页面
        closeMoal: function () {
            $('#setFormId').data('bootstrapValidator').resetForm(true);
            //$('#setFormId').reset();
            $('#setFormModal').modal('hide');
        },
        //导出
        exportFile: function () {


        },
        //审核
        setUser: function (id) {
            $('#setUserModal').modal('show');
            planDetailId = id;
            getZcxUserListB("userId3", 3);
            var columns = [[
                {field: 'ck', width: '2%', checkbox: false, align: 'center',},
                {field: 'id', title: 'id', width: 10, align: 'center', visible: false},
                {title: '计划详情ID', field: 'planDetailId', align: 'center', valign: 'middle', visible: false},
                {title: '分配人员', field: 'userId', align: 'center', valign: 'middle', visible: false},
                {title: '分配人员', field: 'name', align: 'center', valign: 'middle', visible: true},

                {
                    title: '操作',
                    field: 'opt',
                    align: 'center',
                    valign: 'middle',
                    visible: true,
                    formatter: function (value, row, index) {
                        var html = '';
                        /* '<button class="btn-white btn btn-xs">查看</button>'+ */
                        html += '<button id="edit_btn" class="btn btn-outline-secondary btn-sm"  onclick="operationUser.editWindow(' + index + ')">编辑</button>';
                        html += '<button class="btn btn-outline-secondary btn-sm"  onclick="operationUser.deleteFrom(' + index + ')">删除</button>';
                        return html;
                    }
                },
            ]];

            $('#dgUser').bootstrapTable("destroy");
            $('#dgUser').bootstrapTable({
                url: "/ZcxPlanDetailUser/query",
                sidePagination: "server",
                queryParams: function (params) {
                    var temp = getFormJson("searchForm");
                    temp.rows = params.limit;
                    temp.planDetailId = id;
                    temp.currentPage = (params.offset / params.limit) + 1;
                    return temp;

                },
                method: "post",
                contentType: "application/x-www-form-urlencoded",
                pagination: true,
                pageNumber: 1,
                pageSize: 10,
                pageList: [10, 25, 50, 100],
                //search:true,
                clickToSelect: true,
                singleSelect: true,
                toolbar: '#toolbar',
                columns: columns,
            })


        },


    }

    var operationUser = {
        searchForm: function () {
            $('#dgUser').bootstrapTable("refresh");
        },
        //弹出添加页面
        addWindow: function () {
            $('#setUserFormModal').modal('show');
            formObj.setBtnIsShow("user_add_save_btn", "user_edit_save_btn", 1);
            getZcxUserListB("userId3", 3);
        },
        //添加表单
        addForm: function () {
            $("#setUserFormId").bootstrapValidator('validate');
            if ($("#setUserFormId").data("bootstrapValidator").isValid()) {
                var temp = getFormJson("setUserFormId");

                temp.planDetailId = planDetailId;
                $.post("/ZcxPlanDetailUser/insertZcxPlanDetailUser", temp, function (data) {

                    $("#dgUser").bootstrapTable("refresh");
                    message.alert(data.showInfo);
                    $('#setUserFormId').data('bootstrapValidator').resetForm(true);
                    $('#setUserFormId')[0].reset();
                    $('#setUserFormModal').modal('hide');
                });
            }

        },
        //弹出修改页面
        editWindow: function (index) {
            var row = $("#dgUser").bootstrapTable("getData")[index];
            setForm("#setFormId", row);
            $('#setUserFormModal').modal('show');
            formObj.setBtnIsShow("user_add_save_btn", "user_edit_save_btn", 0);

        },
        //修改表单
        editForm: function () {
            var validate = $("#setUserFormId").bootstrapValidator('validate');
            if ($("#setUserFormId").data("bootstrapValidator").isValid()) {
                var temp = getFormJson("setUserFormId");
                $.post("/ZcxPlanDetailUser/updateZcxPlanDetailUser", temp, function (data) {

                    $("#dgUser").bootstrapTable("refresh");
                    message.alert(data.showInfo);
                    $('#setUserFormId').data('bootstrapValidator').resetForm(true);
                    $('#setUserFormId')[0].reset();
                    $('#setUserFormModal').modal('hide');
                });
            }

        },
        //删除表单
        deleteFrom: function (index) {
            var row = $("#dgUser").bootstrapTable("getData")[index];


            bootbox.confirm({
                size: "small",
                title: "提示",
                message: "确认删除这条数据吗？",
                callback: function (result) {
                    if (result) {
                        $.post("/ZcxPlanDetailUser/deleteZcxPlanDetailUser", {id: row.id}, function (data) {

                            $("#dgUser").bootstrapTable("refresh");
                            message.alert(data.showInfo);

                        });

                    }
                }
            });


        },
        //关闭页面setUserFormModal  closeMoal
        closeMoal: function () {
            //$('#setUserFormId').data('bootstrapValidator').resetForm(true);
            //$('#setFormId').reset();
            $('#setUserFormModal').modal('hide');
        },
        //导出
        exportFile: function () {


        },
        //审核
        audit: function () {


        },


    }


    $(function () {
        //表格格式化
        var fmt = {
            queryParams: function (params) {
                var temp = getFormJson("searchForm");
                temp.rows = params.limit;
                temp.currentPage = (params.offset / params.limit) + 1;
                return temp;

            },
            setTime: function (value, row, index) {

                return formatTimeYMDhms(value);  //转成年月日时分秒
            },
            setOpt: function (value, row, index) {
                var html = '';
                /* '<button class="btn-white btn btn-xs">查看</button>'+ */
                html += '<button class="btn btn-outline-secondary btn-sm"  onclick="operation.setUser(' + row.id + ')">设置检修员</button>';

                html += '<button id="edit_btn" class="btn btn-outline-secondary btn-sm"  onclick="operation.editWindow(' + index + ')">编辑</button>';
                html += '<button class="btn btn-outline-secondary btn-sm"  onclick="operation.deleteFrom(' + index + ')">删除</button>';


                return html;
            },
            setActImgUrl: function (value, row, index) {
                return '<img src="/TBook/queryPic?id=' + row.id + '" style="width:100px;heigth:100px"></img>';
            },
            setBorrow: function (value, row, index) {
                var htm = "";
                if (row.borrow == 0) {
                    htm = "未借阅";
                }
                if (row.borrow == 1) {
                    htm = "<span style='color:red;'>已借阅</span>";
                }
                return htm;
            },
        }

        var columns = [[

            {
                field: 'id',
                title: 'id',
                width: 10,
                align: 'center',
                visible: false
            },


            {title: '计划主键', field: 'planId', align: 'center', valign: 'middle', visible: false},
            {title: '计划名称', field: 'planName', align: 'center', valign: 'middle', visible: true},
            {title: '开始时间', field: 'planStar', align: 'center', valign: 'middle', visible: true},
            {title: '结束时间', field: 'planEnd', align: 'center', valign: 'middle', visible: true},
            {title: '计划类型', field: 'planDetailType', align: 'center', valign: 'middle', visible: true},
            {title: '详情信息', field: 'planDetailInfo', align: 'center', valign: 'middle', visible: true},
            {title: '计划详情状态', field: 'planDetailStatus', align: 'center', valign: 'middle', visible: true},
            {title: '机车Id', field: 'trainInfoId', align: 'center', valign: 'middle', visible: false},
            {title: '机车', field: 'trainNo', align: 'center', valign: 'middle', visible: true},
            {title: '计划清单', field: 'repairTypeId', align: 'center', valign: 'middle', visible: false},
            {title: '计划清单', field: 'repairTypeName', align: 'center', valign: 'middle', visible: true},

            {title: '创建时间', field: 'createTime', align: 'center', valign: 'middle', visible: true},
            {title: '操作', field: 'opt', align: 'center', valign: 'middle', visible: true, formatter: fmt.setOpt},


        ]];


        $('#dg').bootstrapTable({
            url: "/ZcxPlanDetail/query",
            sidePagination: "server",
            queryParams: fmt.queryParams,
            method: "post",
            contentType: "application/x-www-form-urlencoded",
            pagination: true,
            pageNumber: 1,
            pageSize: 10,
            pageList: [10, 25, 50, 100],
            //search:true,
            clickToSelect: true,
            singleSelect: true,
            toolbar: '#toolbar',
            columns: columns,
        })

    });


    $(function () {
        $("#setFormId").bootstrapValidator({
            /* live:'disabled',
            excluded:[':disabled'],
            feedbackIcons: {
        　　　　　　　　valid: 'glyphicon glyphicon-ok',
        　　　　　　　　invalid: 'glyphicon glyphicon-remove',
        　　　　　　　　validating: 'glyphicon glyphicon-refresh'
    　　　　　   },*/
            fields: {


                planId: {
                    validators: {
                        notEmpty: {
                            message: "计划主键不能为空!",
                        },
                    }

                },


                planDetailType: {
                    validators: {
                        notEmpty: {
                            message: "计划类型不能为空!",
                        },
                    }

                },


                planDetailInfo: {
                    validators: {
                        notEmpty: {
                            message: "详情信息不能为空!",
                        },
                    }

                },


                planDetailStatus: {
                    validators: {
                        notEmpty: {
                            message: "计划详情状态不能为空!",
                        },
                    }

                },


                trainInfoId: {
                    validators: {
                        notEmpty: {
                            message: "机车Id不能为空!",
                        },
                    }

                },


                createTime: {
                    validators: {
                        notEmpty: {
                            message: "创建时间不能为空!",
                        },
                    }

                },


            }

        });


    })


</script>

</body>

</html>
